function FlowPedia()
{
   // general configuration
   // full URI of your statusNet instance:
   this.statusnetURI = "http://www.example.com/statusnet/index.php/";
   // full URI of your MediaWiki instance:
   this.mediawikiURI = "http://www.example.com/wiki/";
   // how is the Mediawiki-Feature "Categories" called in your language?
   this.categoryName = "Kategorie";
   // filename for loading graphic, must be stored in FlowPedia extension directory
   this.loading = "flowpedia_loading.gif";

   // DO NOT CHANGE ANYTHING FROM HERE!

   this.transformDate = function(date)
   {
      var datum = new Date(date);
      
      return datum.getDate()+'.'+datum.getMonth()+'.'+(datum.getYear() < 999 ? datum.getYear()+1900 : '')+', '+datum.getHours()+':'+datum.getMinutes()+' Uhr';
   }
   
   this.applyView = function(param)
   {
      switch(param)
      {
         case 'list':
            document.getElementById('flowpedia_microblogging').innerHTML = flowpedia_data.getOutList();
            break;
         case 'cells':
         default:
            document.getElementById('flowpedia_microblogging').innerHTML = flowpedia_data.getOutCells();
            break;
      }
   }
}

// do not change from here!

function FlowPediaData()
{
   var out_list, out_cells, out_general;
   
   this.setOutList = function(data)
   {
      out_list = data;
   }
   
   this.setOutCells = function(data)
   {
      out_cells = data;
   }
   
   this.setOutGeneral = function(data)
   {
      out_general = data;
   }
   
   this.getOutList = function()
   {
      return out_general + out_list + '<br style="clear: both;"/></div>';
   }
   
   this.getOutCells = function()
   {
      return out_general + out_cells + '<br style="clear: both;"/></div>';
   }
}

function FlowPediaAjax(skript, useOnlyGet)
{
   var post, fkt, para, transform,
   header = [],
   vars = [[],[]],
   req = null,
   response = null,
   gut = false;

   header[0] = ['Content-Type', 'application/x-www-form-urlencoded'];
   header[1] = ['Method', (typeof useOnlyGet == 'undefined' ? 'post ' : 'get ') + skript + ' HTTP/1.1'];
   header[2] = ['Charset', 'utf-8'];

   this.addVar = function(name, value, sendType)
   {
      sendType = typeof useOnlyGet == 'undefined' ? (sendType == 1 ? 1 : 0) : 0;
      vars[sendType][vars[sendType].length] = [encodeURIComponent(name), encodeURIComponent(value)];
   }

   this.addHeader = function(name, value)
   {
      header[header.length] = [name, value];
   }

   this.setFunktion = function(name,param)
   {
      fkt = name;
      para = param;
   }

   this.senden = function()
   {
      var j, i, daten = ['', ''];

      if(window.XMLHttpRequest)
      {
         req = new XMLHttpRequest();
      }
      else if(window.ActiveXObject)
      {
         try
         {
            req = new ActiveXObject('Msxml2.XMLHTTP');
         }
         catch(ex)
         {
            try
            {
               req = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch(ex)
            {
            }
         }
      }

      for(j = 0; j < (typeof useOnlyGet == 'undefined' ? 2 : 1); j++)
      {
         if(vars[j].length > 0)
         {
            for(i = 0; i < vars[j].length; i++)
            {
               daten[j] += vars[j][i][0] + '=' + vars[j][i][1] + ((i < vars[j].length - 1) ? '&' : '');
            }
         }
      }

      if(typeof useOnlyGet == 'undefined')
      {
         req.open('POST', skript + (vars[0].length > 0 ? '?' + daten[0] : ''), true);
         req.setRequestHeader('Content-Length', daten[1].length);
      }
      else
      {
         req.open('GET', skript + (vars[0].length > 0 ? '?' + daten[0] : ''), true);
      }

      for(i = 0; i < header.length; i++)
      {
         req.setRequestHeader(header[i][0], header[i][1]);
      }

      req.onreadystatechange = function()
      {
         if(req.readyState == 4)
         {
            if(req.status == 200)
            {
               //if(gut && typeof fkt != 'undefined')
               if(typeof fkt != 'undefined')
               {
                  if(typeof para != 'undefined')
                  {
                     fkt.apply(null,para);
                  }
                  else
                  {
                     fkt();
                  }
               }
            }
            else
            {
               req.abort();
            }
         }
         else if(req.readyState == 3 && req.status == 303)
         {
               req.abort();
         }
      }

      req.send(typeof useOnlyGet == 'undefined' ? daten[1] : null);
   }

   this.res = function()
   {
      var myObject = eval('(' + req.responseText + ')');
      return myObject;
      //return transform(response['c']);
   }

   transform = function(f)
   {
      if(typeof f == 'Object')
      {
         for(i in f)
         {
            f[i] = transform(f[i]);
         }
      }
      else if(typeof f == 'Array')
      {
         for(i = 0; i < f.length; i++)
         {
            f[i] = transform(f[i]);
         }
      }
      else if(typeof f == 'String')
      {
         f = decodeURIComponent(f);
      }

      return f;
   }
}
